//路由鉴权：就是路由能不能被访问到权限设置->全局守卫
import router from  './router/index'
//引入进度条的动画效果
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({showSpinner:false})

import useUserStore from "@/store/mod/user.ts";

import pinia from './store/index.ts'
let userStore= useUserStore(pinia)
let whiteList=['/home','/hospital/register','/hospital/detail','/hospital/notice','/hospital/close','/hospital/search','/wxlogin']
router.beforeEach((to, from, next)=>{
    NProgress.start();
    document.title=`尚医通-${to.meta.title}`
    let token = userStore.userInfo.token
    if(token){
        next()
    }else {
        if(whiteList.includes(to.path)){
            next()
        }else {
            userStore.visiable=true
            next({path:'/home',query:{redirect:to.fullPath}})
        }
    }
})

router.afterEach((to, from, next)=>{
    NProgress.done();
})